#!/bin/bash

export user=forlinx
export passwd=forlinx
export addr=192.168.8.112

export CSV_NAME=D500Trans.csv
export TS_PATH=../res/views/linuxts
export JS_PATH=~/proc/buildtool/excel2ts/csv2ts.js
export TARGET_PATH=~/Documents

# 将 csv 文件传到出包服务器
expect -c "
spawn scp $TS_PATH/$CSV_NAME $user@$addr:$TARGET_PATH
expect {
    \"*assword:\" {
        send \"$passwd\r\"
        exp_continue
    }
    \"yes/no\" {
        send \"yes\r\"
        exp_continue
    }
    eof
}
"

# csv 生产 ts 文件
expect -c "
spawn ssh $user@$addr node $JS_PATH $TARGET_PATH/$CSV_NAME $TARGET_PATH
expect {
    \"*assword:\" {
        send \"$passwd\r\"
        exp_continue
    }
    \"yes/no\" {
        send \"yes\r\"
        exp_continue
    }
    eof
}
"

# 将 ts 文件传到本地
expect -c "
spawn scp  $user@$addr:$TARGET_PATH/*.ts $TS_PATH
expect {
    \"*assword:\" {
        send \"$passwd\r\"
        exp_continue
    }
    \"yes/no\" {
        send \"yes\r\"
        exp_continue
    }
    eof
}
"

# 删除出包服务器文件
expect -c "
spawn ssh $user@$addr rm $TARGET_PATH/*.ts $TARGET_PATH/$CSV_NAME
expect {
    \"*assword:\" {
        send \"$passwd\r\"
        exp_continue
    }
    \"yes/no\" {
        send \"yes\r\"
        exp_continue
    }
    eof
}
"
